package com.yvon.core.page;

import com.google.common.collect.Sets;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Set;

@Data
@NoArgsConstructor
public abstract class BaseSearchCriteria implements Serializable {
    private static final long serialVersionUID = 6686103841929106216L;
    private static final long DEFAULT_PAGE = 1L;
    private static final long DEFAULT_SIZE = 10L;
    private long page = 1L;
    private long size = 10L;
    private List<OrderParam> orderParams;
    private Set<SearchParam> searchParams;

    public void addSearchParam(SearchParam searchParam) {
        if (Objects.isNull(this.searchParams)) {
            this.searchParams = Sets.newHashSet(new SearchParam[]{searchParam});
        } else {
            this.searchParams.removeIf((next) -> next.getFieldName().equals(searchParam.getFieldName()));
            this.searchParams.add(searchParam);
        }
    }
}
